@extends('backend.master')

@section('content')
	<h2>{{$title}}</h2>

	<div class="search">
		{{Form::open(array("method"=>"get","class"=>"form-inline"))}}
			<div class="form-group">
				<label class="sr-only" for="exampleInputEmail2">Email address</label>
				{{Form::text("search",Input::get("search"),array("class"=>"form-control","id"=>"exampleInputEmail2","placeholder"=>"Tìm kiếm..."))}}
			</div>
			{{Form::submit("Search",array("class"=>"btn btn-default"))}}
		{{Form::close()}}
	</div>

	@if (count($products) > 0)
	<table class="table table-bordered table-striped table-hover">
		<tr>
			<a href="{{URL::route('create_product_get')}}" class="btn btn-primary" >Thêm bài viết</a>
		</tr>

		@if ($search != "")
			<p>Tìm thấy <span style='color:red'>{{count($products)}}</span> sản phẩm</p>
		@endif

		<tr class="info">
			<td>Title</td>
			<td>Description</td>
			<td>Content</td>
			<td>Images</td>
			<td>Price</td>
			<td>Categories</td>
			<td>Users</td>
			<td>Edit</td>
			<td>Delete</td>
		</tr>

		@foreach($products as $product)
			<tr>
				<td>{{$product->title}}</td>
				<td>{{Str::limit($product->description,100)}}</td>
				<td>{{Str::limit($product->content,200)}}</td>
				<td><img src="{{$product->img}}" style="width:80px;height:80px" class="img-thumbnail"></td>
				<td>{{Currency::format($product->price,'VND','')}}</td>
				<td>{{$product->cateproducts->title}}</td>
				<td>{{$product->users->username}}</td>
				<td><a href="{{URL::route('edit_product_get',array($product->id))}}"><img src="{{URL::to('/')}}/public/backend/images/edit.png" ></a></td>
				<td><a href="{{URL::route('delete_product',array($product->id))}}" onclick='return confirm_delete("do you want to delete this categorie ?")'><img src="{{URL::to('/')}}/public/backend/images/delete.png" ></a></td>
			</tr>
		@endforeach

	</table>

	@if ($search != "")
		<a href="{{URL::route('list_product')}}" class="btn btn-success">Trở lại danh sách sản phẩm</a>
	@endif

	{{ $products->appends(array('search' => $search))->links() }}

	@else
		<table class="table table-bordered table-striped table-hover">
			<tr class="info">
				<td>Title</td>
				<td>Description</td>
				<td>Content</td>
				<td>Images</td>
				<td>Price</td>
				<td>Categories</td>
				<td>Users</td>
				<td>Edit</td>
				<td>Delete</td>
			</tr>
			<tr>
				<td colspan="9" align="center"><p class="alert alert-danger">Không tìm thấy bản ghi nào	</p></td>
			</tr>
		</table>
		
	@endif

	

@endsection

@section("data_code")
	<script language="javascript">
		function confirm_delete(err){
			if(!window.confirm(err)){
				return false;
			}
		}
	</script>
@endsection